import { registerHandlers, run, type Handler } from "encore.dev/internal/codegen/appinit";
import { Worker, isMainThread } from "node:worker_threads";
import { fileURLToPath } from "node:url";
import { availableParallelism } from "node:os";

{{#each endpoints}}
import { {{name}} as {{name}}Impl{{@index}} } from {{toJSON import_path}};
{{/each}}
{{#each subscriptions}}
import {{toJSON import_path}};
{{/each}}
{{#with service}}
{{#if import_path}}
import * as {{encoreNameToIdent name}}_service from {{toJSON import_path}};
{{/if}}
{{/with}}

const handlers: Handler[] = [
{{#each endpoints}}
    {
        apiRoute: {
            service:           {{toJSON ../name}},
            name:              {{toJSON name}},
            handler:           {{name}}Impl{{@index}},
            raw:               {{toJSON raw}},
            streamingRequest:  {{toJSON streaming_request}},
            streamingResponse: {{toJSON streaming_response}},
        },
        endpointOptions: {{toJSON endpoint_options}},
        middlewares: {{#if ../service.import_path}}{{encoreNameToIdent ../service.name}}_service.default.cfg.middlewares || {{/if}}[],
    },
{{/each}}
];

registerHandlers(handlers);

await run(import.meta.url);
